package com.guigu.leizihao.controller;

import com.guigu.common.pojo.SGatherDetails;
import com.guigu.common.pojo.SPay;
import com.guigu.common.pojo.SPayDetails;
import com.guigu.common.vo.SearchVo;
import com.guigu.leizihao.service.SpayService;
import com.guigu.leizihao.vo.SGatherVo;
import com.guigu.leizihao.vo.SpayDetailsView;
import com.guigu.leizihao.vo.SpayView;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/spay")
public class SpayController {

    @Resource
    private SpayService spayService;

    /**
     * 添加出库单和出库明细
     * @param sGatherVo
     * @return
     */
    @RequestMapping("/addSpayApplyFor")
    @ResponseBody
    public int addSpayApplyFor(@RequestBody SGatherVo<SPayDetails> sGatherVo){
        System.out.println(sGatherVo);
        this.spayService.addSpayApplyFor(sGatherVo);
        return 1;
    }


    @RequestMapping("/changeSpayNo")
    @ResponseBody
    public  int changeSpayNo(Integer id){
        this.spayService.changeSpayNo(id);
        return 1;
    }

    /**
     * 查询所有待审核的出库单
     * @param searchVo
     * @return
     */
    @RequestMapping("/queryspayToAudit")
    @ResponseBody
    public SearchVo queryspayToAudit(SearchVo searchVo){

        SearchVo s= this.spayService.queryspayToAudit(searchVo);
        System.out.println(s);
        return s;
    }

    /**
     * 根据出库单编号查询对应的出库明细
     * @param id
     * @return
     */
    @RequestMapping("/findSpayDetailsById")
    @ResponseBody
    public List<SpayView> findSpayDetailsById(Integer id){

        return this.spayService.findSpayDetailsById(id);
    }


    @RequestMapping("/changeSpay")
    @ResponseBody
    public int changeSpay(@RequestBody SPay sPay){
        System.out.println(sPay);
        int i=  this.spayService.changeSpay(sPay);
        return 1;
    }

    /**
     * 查询所有的出库申请单
     * @param searchVo
     * @return
     */
    @RequestMapping("/querySpayAll")
    @ResponseBody
    public SearchVo querySpayAll(@RequestBody SearchVo searchVo){

      return   this.spayService.querySpayAll(searchVo);
    }


    @RequestMapping("/findFormulateSpay")
    @ResponseBody
    public SearchVo findFormulateSpay(SearchVo searchVo){
        return  this.spayService.findFormulateSpay(searchVo);
    }


    /**
     * 更改明细状态
     * @param id
     * @return
     */
    @RequestMapping("/UpdateSpay_details")
    @ResponseBody
    public int UpdateSpay_details(Integer id){

         int i=   this.spayService.UpdateSpay_details(id);
            return 1;
    }

    /**
     * 查询所有的已调度完的出库申请单
     * @return
     */
    @RequestMapping("/querySpayOut")
    @ResponseBody
    public  SearchVo querySpayOut(SearchVo searchVo){

       return this.spayService.querySpayOut(searchVo);

//        return null;
    }

    /**
     * 更改明细的本次出库数量
     * @param sGatherVo
     * @return
     */
    @RequestMapping("/updateSpay_detailsQuantityInStorage")
    @ResponseBody
    public int updateSpay_detailsQuantityInStorage(@RequestBody SGatherVo sGatherVo){
           this.spayService.updateSpay_detailsQuantityInStorage(sGatherVo);
            return 1;
    }

    /**
     * 查询已申请本次出库数量的出库申请单
     * @param searchVo
     * @return
     */
    @RequestMapping("/queryOutboundCheck")
    @ResponseBody
    public  SearchVo queryOutboundCheck(SearchVo searchVo){
        return this.spayService.queryOutboundCheck(searchVo);
    }

    /**
     * 根据id查询已申请本次出库数量的出库申请单明细
     * @param id
     * @return
     */
    @RequestMapping("/findSpayDetailsByIdandQuantityIinStorage")
    @ResponseBody
    public List<SpayView>  findSpayDetailsByIdandQuantityIinStorage(Integer id){
        return this.spayService.findSpayDetailsByIdandQuantityIinStorage(id);
    }


    @RequestMapping("/OutboundCheckPass")
    @ResponseBody
    public int OutboundCheckPass(@RequestBody SGatherVo<SPayDetails> sGatherVo){

        this.spayService.OutboundCheckPass(sGatherVo);

        return 1;
    }

    @RequestMapping("/querySpayTotalcost")
    @ResponseBody
    public Integer querySpayTotalcost(Integer id){
        return this.spayService.querySpayTotalcost(id);
    }

    @RequestMapping("/queryspayDetailsByproductId")
    @ResponseBody
    public List<SpayDetailsView> queryspayDetailsByproductId(String productid){
        return this.spayService.queryspayDetailsByproductId(productid);
    }
}
